package com.lagou.demo;

import com.lagou.demo.bean.Resume;
import com.lagou.demo.dao.ResumeDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        ApplicationContext applicationContext  = SpringApplication.run(DemoApplication.class,args);
        ResumeDAO resumeDao = applicationContext.getBean("resumeDao",ResumeDAO.class);

        testInsert(resumeDao);

        testQuery(resumeDao);
    }

    private static void testQuery(ResumeDAO resumeDao) {
        System.out.println("查询数据");
        Resume  resume2  =resumeDao.findByName("小李");
        System.out.println(resume2);
    }

    private static void testInsert(ResumeDAO resumeDao) {
        System.out.println("插入数据");
        Resume resume  = new Resume();
        resume.setName("小李");
        resume.setCity("北京");
        Date date = null;
        String  dateStr = "yyyy-MM-dd hh:mm:ss";
        SimpleDateFormat simpleDateFormat  = new SimpleDateFormat(dateStr);
        try {
            date = simpleDateFormat.parse("2003-11-02 11:13:14");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        resume.setBirthday(date);
        resume.setExpectSalary(28000);
        resumeDao.insertResume(resume);
        System.out.println("resume="+resume);

    }


}
